<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	.item{
		width: 120px;
		display: inline-block;
		margin-left: 5px;
	}
    </style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table  width="100%" border="0">
	    	 <tr>
			    <td style="width:30%;">
			      <span class="item">客服组：</span>
			      <input id="cur_ser_group" showNullItem="true" emptyText="请选择..." nullItemText="全部" class="mini-combobox" style="width:160px;" textField="name" valueField="id" url="sms_find_group.do" onvaluechanged="onDeptChanged" />
			    </td>
			    <td style="width:30%;">
			      <span class="item">发送坐席：</span>
			      <input id="sendSeat" class="mini-combobox" emptyText="请先选择客服组" style="width:160px;" textField="name" valueField="id"/>
			    </td>
			   	<td style="width:30%;">
			   	  <span class="item">接收手机号（精确）：</span>
			      <input id="phoneNum" class="mini-textbox" emptyText="请输入手机号码"  style="width:160px;"/>
			    </td>
			 </tr>
			 <tr>   
			   	<td style="width:30%;" colspan="3">
			   	  <span class="item">发送状态（精确）：</span>
			      <input id="sendStatus" showNullItem="true" nullItemText="全部" class="mini-combobox"  emptyText="请选择..." url="dictionary_cm_key_val_view.do?typeName=SMS_STATUS_TYPE"  valueField="keyName" textField="keyValue" style="width:160px;"/>
			    </td>
			    <td style="white-space:nowrap;"><a class="mini-button" iconCls="icon-search" onclick="search()">查询</a></td>
			 </tr>
	    </table>  
	</div> 
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	  <table style="width:100%;">
		<tr>
			<td>
				<sec:authorize url='/export_center_current.do'>
		        <a class="mini-button" iconCls="icon-download" onclick="exportCurrent()">导出当前</a>
		        </sec:authorize>
		        <sec:authorize url='/export_center_all.do'>
		        <a class="mini-button" iconCls="icon-download" onclick="exportAll()">导出所有</a>
		        </sec:authorize>
			</td>
		</tr>
	</table>
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" url="sms_center_view.do" style="width:100%;height:100%;" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div name="action" width="10%" headerAlign="center" align="center" renderer="onActionRenderer">相关操作</div>
			<div field="phoneNum" width="10%" headerAlign="center" align="center">接收手机号</div>
			<div field=content width="30%" headerAlign="center" align="center">接收内容</div>
			<div field="sendSeatName" width="10%" headerAlign="center" align="center">发送坐席</div>
			<div field="createTime" width="15%" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" align="center">创建时间</div>
			<div field="sendTime" width="15%" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" align="center">发送时间</div>
			<div field="statusVal" width="10%" headerAlign="center" align="center">发送状态</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();

function onActionRenderer(e) {
	return '<a style="width:150px;" href="javascript:viewDetail()">查看详细</a>';
}

function viewDetail(){
	var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "sms_center_view_detail.do",
            title: "短信详细信息", width: 600, height: 400,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "viewDetail", row: row };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: false,
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
            }
        });
    } else {
        alert("请选中一条记录");
    }
}
function search() {
    var phoneNum = mini.get("phoneNum").getFormValue();
    var sendStatus = mini.get("sendStatus").getFormValue();
    var sendSeat = mini.get("sendSeat").getFormValue();
    var cur_ser_group = mini.get("cur_ser_group").getFormValue();
    grid.load({ phoneNum: phoneNum,
    	sendStatus: sendStatus,
    	sendSeat: sendSeat,
    	groupId:cur_ser_group,
    });
}

function exportAll() {
	var phoneNum = mini.get("phoneNum").getFormValue();
    var sendStatus = mini.get("sendStatus").getFormValue();
    var sendSeat = mini.get("sendSeat").getFormValue();
    var cur_ser_group = mini.get("cur_ser_group").getFormValue();
   	location.href="export_center_all.do?phoneNum="+phoneNum+"&sendStatus="+sendStatus+"&sendSeat="+sendSeat+"&groupId="+cur_ser_group; 
}

function exportCurrent(){
	var data =grid.getData();
	var ids = [];
	$.each(data , function(){
        ids.push(this.id);
    });
	 var id = ids.join(',');
	 location.href="export_center_current.do?ids=" +id;
}

function onDeptChanged(e) {
	var curSer = mini.get("sendSeat");
	curSer.setValue("");
    var url = "sms_cur_ser.do?groupId=" + e.value;
    curSer.setUrl(url);
}
</script>
</body>
</html>